<!DOCTYPE html>
<html>
<meta charset="utf-8">
<meta content="IE=9" http-equiv="x-ua-compatible">
<head th:include="include :: header"></head>
<style>
    .se{
        width: 30%;
        float: left;
        margin: 5px 5px 5px 5px;
    }

    .ina{
        width: 60%;
        float: left;
        text-align: center;
        margin: 5px 5px 5px 5px;
    }

</style>
<body class="gray-bg">
<div class="wrapper wrapper-content ">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-content">
                    <form class="form-horizontal m-t" id="signupForm">
                        <input id="id" name="id" th:value="${id}"  type="hidden">
                       <!-- <input id="tableName" name="tableName" th:value="${tableName}"  type="hidden">-->
                        <!--<input id="status" name="status" th:value="${orderOrder.status}"  type="hidden">-->
                        <!--<div class="form-group">
                            <label class="col-sm-3 control-label">物流名称：</label>
                            <div class="col-sm-8">
                                <select id="shippingName" name="shippingName" class="form-control">
                                    <option th:each = "list:${codeList}" th:text="${list.name}" th:value="${list.code}"></option>
                                </select>
                            </div>
                            &lt;!&ndash;<div class="col-sm-8">
                                <select id="shippingName" name="shippingName" class="form-control">
                                    <option th:each="tList : ${shopExpressCodeList}" th:value="${tList.name}"><span th:text="${tList.name}"></span></option>
                                </select>
                            </div>&ndash;&gt;
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">物流单号：</label>
                            <div class="col-sm-8">
                                <input id="shippingCode" name="shippingCode" class="form-control" type="text">
                            </div>
                        </div>-->
                        <button id="groupAdd" type="button" class="btn btn-primary"><i class="fa fa-plus mr5"></i>添加参数组</button>
                        <div style="width: 100%">
                            <div style="width: 30%; float: left;text-align: center">
                                物流名
                            </div>
                            <div style="width: 60%; float: left;text-align: center">
                                物流单号
                            </div>
                        </div>
                        <div id="ccc">
                            <div class="can shili">
                                <select class="form-control se">
                                    <option th:each = "list:${codeList}" th:text="${list.name}" th:value="${list.code}"></option>
                                </select>
                                <input type="text" value="" placeholder="物流单号" required="required"  class="form-control ina">
                                <div class="del fa fa-remove" onclick="del(this)" style="cursor:pointer;float: left;margin: 15px 15px;" title="删除"></div>
                            </div>
                        </div>

                        <div class="form-group">
                            <div class="col-sm-8 col-sm-offset-3">
                                <button type="submit" class="btn btn-primary">提交</button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
<div th:include="include::footer"></div>
<script th:inline="javascript">
/*
    var codeList = [[${codeList}]];
*/
    $().ready(function() {
        validateRule();
        var str = $('#ccc').html();
        //添加物流
        $('#groupAdd').on('click', function() {
            $('#ccc').append(str);
        })

        //删除物流
        /*$('#ccc').on('click', ".del", function() {
            console.log("sadas");
            $(this).parent().remove();
        })*/
    });

    function del(a) {
        console.log($(a).parent());
        $(a).parent().remove();
    }

    $.validator.setDefaults({
        submitHandler : function() {
            shipments();
        }
    });
    function shipments() {
        var se = document.getElementsByClassName('se');
        var ina = document.getElementsByClassName('ina');
        var datail = [];
        for (var i=0; i<se.length; i++) {
            var shipping = "";
            shipping = se[i].value;
            shipping += ":"+ina[i].value
            datail.push(shipping);
        }
        console.log("se.length"+se.length);
        console.log("datail:"+datail);
        layer.confirm('此项操作会删除以前的物流信息，确定要继续吗？', {
            btn : [ '确定', '取消' ]
        }, function() {
            $.ajax({
                cache: true,
                type: "POST",
                url: "/wx/orderOrder/modifyOrderT",
                data: {
                    "datail": datail.toString(),
                    "orderId": $('#id').val()

                },
                async: false,
                error: function (request) {
                    parent.layer.alert("Connection error");
                },
                success: function (data) {
                    if (data.code == 0) {
                        parent.layer.msg("操作成功");
                        parent.reLoad();
                        var index = parent.layer.getFrameIndex(window.name); // 获取窗口索引
                        parent.layer.close(index);

                    } else {
                        parent.layer.alert(data.msg)
                    }

                }
            });
        })
    }
    function validateRule() {
        var icon = "<i class='fa fa-times-circle'></i> ";
        $("#signupForm").validate({
            /*rules : {
                shippingName : {
                    required : true
                },
                shippingCode : {
                    required : true
                }
            },
            messages : {
                shippingName : {
                    required : icon + "请选择物流名称"
                },
                shippingCode : {
                    required : icon + "请输入物流单号"
                }

            }*/
        })
    }

</script>
</body>
</html>
